<?php
/**
 * Created by PhpStorm.
 * User: yhb
 * Date: 2019/3/4
 * Time: 9:36
 */

namespace app\admin\model;


use think\Model;
use think\Db;

class Common extends Model
{
    protected $table;

    public function __construct($data = [])
    {
        parent::__construct($data);
    }

    /**添加数据
     * @param array $data
     * @return int|string
     */
    public function addData($data = array())
    {
        return Db::name($this->table)->insert($data);
    }

    /**更新数据
     * @param array $data 要更新的数据
     * @param array $where 更新条件
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function saveDate($data = array(), $where = array())
    {
        return Db::name($this->table)->where($where)->update($data);
    }

    /**删除数据
     * @param array $where 删除条件
     * @return int
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function delData($where = array())
    {
        return Db::name($this->table)->where($where)->delete();
    }

    /**查询一条数据
     * @param array $where 查询条件
     * @param string $filed 查询字段列表
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getOne($where = array(), $filed = '*')
    {
        return Db::name($this->table)->where($where)->field($filed)->find();
    }
    public function getAll($where=array(),$field='*'){
        return Db::name($this->table)->where($where)->field($field)->select();
    }
}